#ifndef __VIEW_BITMAP_H
#define __VIEW_BITMAP_H

#include <driver/view/color.h>
#include<driver/view/screen.h>
#include<driver/view/region.h>

typedef struct
{
    uint32_t width;
    uint32_t height;
    view_color_t *bits;
} view_bitmap_t;

typedef struct
{
    uint32_t width;
    uint32_t height;
    uint32_t *bits;
} uview_bitmap_t;

typedef struct
{
    int x;
    int y;
    int bx;
    int by;
    int bw;
    int bh;
    uview_bitmap_t bmp;
    uint8_t refresh;
} uview_io_t;

#define ViewBitmapGetPixelFast(bmp,x,y) ((bmp)->bits[(y)*(bmp)->width+(x)])

static inline void ViewBitmapInit(view_bitmap_t *bmp, uint32_t width, uint32_t height, view_color_t *color)
{
    bmp->width = width;
    bmp->height = height;
    bmp->bits = color;
}

static inline void ViewBitmapPutpixelUnsafe(view_bitmap_t *bmp, int x, int y, view_color_t color)
{
    bmp->bits[y * bmp->width + x] = color;
}

static inline void ViewBitmapGetpixelUnsafe(view_bitmap_t *bmp, int x, int y, view_color_t *color)
{
    *color = bmp->bits[y * bmp->width + x];
}

view_bitmap_t *ViewBitmapCreate(uint32_t width, uint32_t height);
int ViewBitmapDestroy(view_bitmap_t *bmp);

void ViewBitmapPutpixel(view_bitmap_t *bmp, int x, int y, view_color_t color);
int ViewBitmapGetpixel(view_bitmap_t *bmp, int x, int y, view_color_t *color);

void ViewBitmapLine(view_bitmap_t *bmp, int x1, int y1, int x2, int y2, view_color_t color);
void ViewBitmapHline(view_bitmap_t *bmp, int x1, int x2, int y, view_color_t color);
void ViewBitmapVline(view_bitmap_t *bmp, int x, int y1, int y2, view_color_t color);

void ViewBitmapRectEx(view_bitmap_t *bmp, int x1, int y1, int x2, int y2, view_color_t color);
void ViewBitmapRectfillEx(view_bitmap_t *bmp, int x1, int y1, int x2, int y2, view_color_t color);
void ViewBitmapRect(view_bitmap_t *bmp, int x, int y, uint32_t width, uint32_t height, view_color_t color);
void ViewBitmapClear(view_bitmap_t *bmp);
void ViewBitmapRectfill(view_bitmap_t *bmp, int x, int y, uint32_t width, uint32_t height, view_color_t color);
void ViewBitmapBlit(view_bitmap_t *src, view_rect_t *src_rect, view_bitmap_t *dst, view_rect_t *dst_rect);

#endif